package com.aop.retry;

/**
 * @Package: com.aop.retry
 * @ClassName: retryDemo
 * @Author: h2cloud
 * @CreateTime: 2022/11/19 12:37 上午
 * @Description:
 */
public class retryDemo {
	public static void main(String[] args) {
		retryDemo r = new retryDemo();
		try {
			r.fun();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public void fun() throws InterruptedException {
		Object ans = new RetryTemplate() {
			@Override
			protected Object doBiz() throws Exception {
				int temp = (int) (Math.random() * 10);
				System.out.println(temp);

				if (temp > 3) {
					throw new Exception("generate value bigger then 3! need retry");
				}

				return temp;
			}
		}.setRetryTime(10).setSleepTime(10).execute();
		System.out.println(ans);
	}
}

